package main

import (
	"fmt"
	"github.com/shirou/gopsutil/cpu"
	"github.com/shirou/gopsutil/disk"
	"github.com/shirou/gopsutil/mem"
	"time"
)

func GetCpuPercent() float64 {
	percent, _:= cpu.Percent(time.Second, false)
	fmt.Printf("Cpu : %d\n", uint8(percent[0]))
	return percent[0]
}

func GetMemPercent() {
	v, _ := mem.VirtualMemory()

	// almost every return value is a struct
	fmt.Printf("Mem : Total: %v, Free:%v, UsedPercent:%v\n", v.Total, v.Free, v.UsedPercent)

	// convert to JSON. String() is also implemented
	//fmt.Println(v)
}

func GetDiskPercent(path string)  {
	usageStat, err := disk.Usage(path)
	if err != nil {
		fmt.Println("get dis failed : ", err)
	}
	fmt.Printf("Disk : %d\n", uint8(usageStat.UsedPercent))
}

func main() {
	GetCpuPercent()
	GetMemPercent()
	GetDiskPercent("/opt")
}